<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
</head>
<body>
<div class="page-container">
    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">

                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">自定义内容列表</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">自定义内容添加</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th>追加次数</th>
                                <th>奖品</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name='data' id='vo' key='k'}
                            <tr>
                                <td>{$vo['loop_num']}</td>
                                <td>{$vo['gift_name']}</td>
                                <input type="hidden" name="prize_id" value="{$vo['prize_id']}">
                                <td>
                                    <button class='sign-rule-member-del btn btn-warning btn-sm btn-margin'>删除</button>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                    </div>

                    <div class=" tab-pane" id="tab-2">
                        <div class="ibox-content">
                            <form class="form-horizontal" enctype="" id="form" >
                                <input type="hidden" name="gold_id" value="{$gold_id}">

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="gift_type">
                                        <span class="c-red">*</span>奖品类型：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <select class="form-control" name="gift_type" id="gift_type">
                                            <option value="1">礼物</option>
                                            <option value="3">道具</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="prize_id">
                                        <span class="c-red">*</span>奖品名称：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <select class="form-control" name="prize_id" id="prize_id">
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="default_stock">
                                        <span class="c-red">*</span>循环轮数：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="number" name="loop_num"  class="form-control" id="default_stock">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                                        <button class="btn btn-primary" type="button" id="btn-submit">添加
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}

<script>

    $(document).ready(function () {
        changeGift(1);
    });

    //自定义内容修改
    $('#gift_type').on('change',function(){
        var gift_type = $(this).val();
        console.log(gift_type);
        changeGift(gift_type);
    });
    //获取奖品名称
    function changeGift(gift_type){
        $.ajax({
            type:'get',
            url:"/changeGift",
            async:true,
            data:{gift_type:gift_type},
            dataType:'json',
            success:function(re){

                var htmlText = "<option value='' selected>--请选择--</option>";
                for(var i in re){
                    htmlText+="<option value="+ re[i].id+">"+ re[i].gift_name+"</option>";
                }
                $('#prize_id').html(htmlText);
            }
        });
    }

    //删除自定义内容
    delDefineContentObj.click(function(){
        var prize_id = $(this).parent().siblings('input').eq(0).val();
        console.log(prize_id);
        layer.confirm('确定删除吗？',{
            title:['提示','font-size:18px;font-family:楷体;font-weight:700;'],
            btn: ['确定','取消'] //按钮
        },function(){
            $.ajax({
                type:'get',
                url:"/LoopSetDataDel",
                async:true,
                data:{prize_id:prize_id,gold_id:gold_id},
                dataType:'json',
                success:function(result){
                    console.log(result);
                    if(result.code == 100){
                        //   parent.layer.close(index);//关闭当前页
                        layer.msg(result.msg,{
                            icon:1,
                            time:1000
                        });
                        window.location.reload();
                    }
                    else{
                        layer.msg(result.msg,{
                            icon:2,
                            time:1000
                        });
                    }
                },
                error:function(err){
                    layer.msg('服务器开小差了！',{
                        time:1500
                    });
                }
            });
        });
    });

    //添加自定义内容
    $('#btn-submit').click(function(){
        console.log($('#form').serialize());
        layer.confirm('确定添加吗？',{
            title:['提示','font-size:18px;font-family:楷体;font-weight:700;'],
            btn: ['确定','取消'] //按钮
        },function(){
            $.ajax({
                type:'post',
                url:'/LoopSetDataAdd',
                async:true,
                data:$('#form').serialize(),
                dataType:'json',
                success:function(result){
                    console.log(result.data);
                    console.log(result.res);
                    if(result.code == 100){
                        //   parent.layer.close(index);//关闭当前页
                        layer.msg(result.msg,{
                            icon:1,
                            time:1000
                        });
                        window.location.reload();
                    }
                    else{
                        layer.msg(result.msg,{
                            icon:2,
                            time:1000
                        });
                    }
                },
                error:function(err){
                    layer.msg('服务器开小差了！',{
                        time:1500
                    });
                    window.location.reload();
                }
            });
        });
    });


</script>
</body>
</html>